package com.wgts.wgts.mvp.view.activity.affrimorder;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.CustomLineaLayoutManager;
import com.wgts.wgts.netmodle.req.OrderLeaveMessage;
import com.wgts.wgts.netmodle.resp.AffirmOrderEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *
 *   data:2018/9/229:33
 *
 */public class AffirmOrderParentAdapter extends RecyclerView.Adapter<AffirmOrderParentAdapter.ViewHold> {
    private Context context;
    private List<AffirmOrderEntity.shop> list;
    private AffirmOrderAdapter adapter;
    private List<OrderLeaveMessage> orderLeaveMessages;

    public AffirmOrderParentAdapter(Context context, List<AffirmOrderEntity.shop> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.affirm_order_parent_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, final int i) {
        if (list.get(i).show){
            viewHold.parentLy.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }else {
            viewHold.parentLy.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));
        }
        //店铺子recycleView adapter
        CustomLineaLayoutManager customLineaLayoutManager = new CustomLineaLayoutManager(context);
        customLineaLayoutManager.setScrollEnabled(false);
        viewHold.shoppingCarRecycle.setLayoutManager(customLineaLayoutManager);
        adapter = new AffirmOrderAdapter(context, list.get(i).products);
        viewHold.shoppingCarRecycle.setAdapter(adapter);
//        MoHuGlide.getInstance().glideImgsFormList(viewHold.shopCarStoreImage, list.get(i).sellerIcon, context);
//        viewHold.shopCarStoreName.setText(list.get(i).sellerName);
        if(list.get(i).getOrderLeaveMessage() == null){
            viewHold.leaveMessageEt.setText("");
        }else{
            viewHold.leaveMessageEt.setText(list.get(i).getOrderLeaveMessage());
        }
        viewHold.leaveMessageEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                list.get(i).setOrderLeaveMessage(s.toString());
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.shop_car_store_image)
        ImageView shopCarStoreImage;
        @BindView(R.id.shop_car_store_name)
        TextView shopCarStoreName;
        @BindView(R.id.watch_store_ly)
        LinearLayout watchStoreLy;
        @BindView(R.id.shop_store_plane_text)
        TextView shopStorePlaneText;
        @BindView(R.id.up_level_ly)
        LinearLayout upLevelLy;
        @BindView(R.id.shop_car_up_level)
        LinearLayout shopCarUpLevel;
        @BindView(R.id.shopping_car_recycle)
        RecyclerView shoppingCarRecycle;
        @BindView(R.id.leave_message_et)
        EditText leaveMessageEt;
        @BindView(R.id.parent_ly)
        LinearLayout parentLy;

        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
